﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;

namespace FR.CodeVisualizer.ObjectSource
{
    public class StreamSerializer
    {
        public static Stream ObjectToStream(Stream outgoingData, object data)
        {
            if (outgoingData == null)
                outgoingData = new MemoryStream();

            BinaryFormatter formatter = new BinaryFormatter();
            formatter.Serialize(outgoingData, data);

            return outgoingData;
        }

        public static object StreamToObject(Stream outgoingData)
        {
            BinaryFormatter formatter = new BinaryFormatter();
            return formatter.Deserialize(outgoingData);
        }
    }
}
